<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ListExpert</title>
<link rel="stylesheet" type="text/css" href="../css/blueprint/screen.css" media="screen, projection"/>
<link rel="stylesheet" type="text/css" href="../css/blueprint/plugins/buttons/screen.css" media="screen, projection"/>
<script type="text/javascript" src="../script/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../script/jquery.plugin.tablecross-0.1.js"></script>
<script type="text/javascript" src="../script/jquery.plugin.pageit-0.1.js"></script>
<script type="text/javascript" src="../script/jquery.plugin.ajaxtip-0.1.js"></script>
<script type="text/javascript">
	var expertTypeHtml = "";
	var queryVO = {name: "", unit: "", type: ""};
    $(document).ready(function() {
        $("#EXPERT_FORM").ajaxProccessTip();
    	getExpertData(queryVO, 1, 10);
    	$("#pageBar").pageListener(getExpertData, queryVO);
    	$("#DELETE_BUTTON").click(function() {
        	if ($(".select_box:checked").length == 0) {
            	alert('请选择要删除的专家');
        	} else {
        		$("#EXPERT_FORM").attr("action", "DeleteExpert.action");
        		$("#EXPERT_FORM").submit();
        	}
    	});
    	$("#EDIT_BUTTON").click(function() {
        	if ($(".select_box:checked").length == 0) {
            	alert('请选择1个要编辑的专家');
        	} else if ($(".select_box:checked").length != 1) {
        		alert('只能选择1个要编辑的专家');
        	} else {
        		$("#EXPERT_FORM").attr("action", "EditExpert.action");
        		$("#EXPERT_FORM").submit();
        	}
    	});
    	$("#QUERY_SELECT").change(function() {
        	if ($(this).val() == "name" || $(this).val() == "unit") {
            	$("#QUERY_TD").html('<input type="text" value="" id="QUERY_CONDITION" />');
        	}
        	if ($(this).val() == "type") {
            	if (expertTypeHtml == "") {
            		$.getJSON("InitExpertType.action", function(data) {
            			var typeArr = new Array();
            			typeArr.push('<select id="QUERY_CONDITION">');
            			typeArr.push('<option value="" selected>选择专家类型</option>');
                        for (var l = 0; l < data.typeList.length; l++) {
                            typeArr.push('<option value="' + data.typeList[l].typeCode + '">' + data.typeList[l].typeName + '</option>');
                        }
                        typeArr.push('</select>');
                        expertTypeHtml = typeArr.join('');
                        $("#QUERY_TD").html(expertTypeHtml);
            		});
            	} else {
            		$("#QUERY_TD").html(expertTypeHtml);
            	}
        	}
    	});
    	$("#QUERY_BUTTON").click(function() {
    		var select = $("#QUERY_SELECT").val();
    		var condition = $("#QUERY_CONDITION").val();
    		if (select == "name") {
    			queryVO.name = condition;
    			queryVO.unit = "";
    			queryVO.type = "";
    		}
    		if (select == "unit") {
    			queryVO.name = "";
    			queryVO.unit = condition;
    			queryVO.type = "";
    		}
    		if (select == "type") {
    			queryVO.name = "";
    			queryVO.unit = "";
    			queryVO.type = condition;
    		}
    		getExpertData(queryVO, 1, 10);
    	});
    });

    function getExpertData(queryVO, pageIndex, pageSize) {
    	$.ajax({
            type: "post",
            url: "ListExpert.action",
            data: {"queryVO.name": queryVO.name, "queryVO.unit": queryVO.unit, "queryVO.type": queryVO.type, "pageVO.pageIndex": pageIndex, "pageVO.pageSize": pageSize},
            dataType: "json",
            success: function(data) {
            	if (data == null) {
                    alert('非法的请求，请确认你是否有权限执行该操作！');
                    return;
                }
            	var strArr = new Array();
                for (var i = 0; i < data.expertList.length; i++) {
                    strArr.push('<tr>');
                    strArr.push('<td><input type="checkbox" name="expertId" class="select_box" value="' + data.expertList[i].expertid + '" /></td>');//号
                    strArr.push('<td>' + data.expertList[i].expertname + '</td>');//姓名
                    strArr.push('<td>' + (data.expertList[i].sex == 0 ? '男' : '女') + '</td>');//性别
                    strArr.push('<td>' + data.expertList[i].unit + '</td>');//单位
                    strArr.push('<td>' + data.expertList[i].typeName + '</td>');//专家类别
                    strArr.push('<td>' + data.expertList[i].tel + '<br/>' + data.expertList[i].mobile + '</td>');//电话
                    strArr.push('<td>' + data.expertList[i].email + '</td>');//电子邮件 
                    strArr.push('<td>' + data.expertList[i].addr + '<br/>' + data.expertList[i].post + '</td>');//地址 
                    strArr.push('</tr>');
                }
                $("#expertDataBody").html(strArr.join(''));
                $("#pageBar").pageRender(data.pageVO.pageIndex, data.pageVO.pageSize, data.pageVO.pageNum);
                $("#expertDataBody").tablecross('', 'odd', 'over');
            }
    	});
    }
</script>
<style type="text/css">
tr.odd td {
    background: #ecf6fc;
}

tr.over td {
    background: #bcd4ec;
}
</style>
</head>
<body>
<form id="EXPERT_FORM" action="" method="post">
<table style="margin-bottom: 10px" width="98%" align="center" cellpadding="0" cellspacing="0">
	<tr>
        <td width="15" style="padding: 0px" align="left">
		    <select id="QUERY_SELECT">
		        <option value="name">姓名</option>
		        <option value="unit">单位</option>
		        <option value="type">专家类别</option>
		    </select></td>
    	<td width="15" id="QUERY_TD"><input type="text" value="" id="QUERY_CONDITION"/></td>
    	<td align="left"><button type="button" id="QUERY_BUTTON"><img src="../css/blueprint/plugins/buttons/icons/magnifier.png" alt=""/>查询</button></td>
    	<td align="left">
    		<button type="button" id="EDIT_BUTTON"><img src="../css/blueprint/plugins/buttons/icons/page_edit.png" alt=""/>编辑专家信息</button>
    		<button type="button" id="DELETE_BUTTON"><img src="../css/blueprint/plugins/buttons/icons/page_delete.png" alt=""/>删除专家信息</button>
    	</td>
    </tr>
</table>
<table id="expertDataTable" style="margin-top: 0px" width="98%" align="center" cellpadding="2" cellspacing="2">
    <thead>
        <tr>
        	<th width="6%">选择</th>
            <th width="8%">姓名</th>
            <th width="6%">性别</th>
            <th width="12%">单位</th>
            <th width="10%">专家类别</th>
            <th width="10%">电话</th>
            <th width="8%">电子邮件</th>
            <th>地址</th>
        </tr>
    </thead>
    <tbody id="expertDataBody">
    </tbody>
    <tbody id="pageBar">
        <tr>
            <td colspan="7" nowrap="nowrap" width="100%">
                <table>
                    <tbody>
                        <tr>
                            <td height="25"><button type="button" class="first-page"><img src="../css/blueprint/plugins/buttons/icons/resultset_first.png" alt=""/></button></td>
                            <td><button type="button" class="previous-page"><img src="../css/blueprint/plugins/buttons/icons/resultset_previous.png" alt=""/></button></td>
                            <td width="20%"><span class="page-index-selector" style=""></span></td>
                            <td><button type="button" class="next-page"><img src="../css/blueprint/plugins/buttons/icons/resultset_next.png" alt=""/></button></td>
                            <td><button type="button" class="last-page"><img src="../css/blueprint/plugins/buttons/icons/resultset_last.png" alt=""/></button></td>
                            <td><select class="page-size-selector">
                                    <option value="10" selected="selected">10</option>
                                    <option value="20">20</option>
                                    <option value="30">30</option>
                                </select></td>
                            <td width="80%">&nbsp;</td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
</table>
</form>
</body>
</html>